// 获取元素
const box = document.querySelector('.box')
const   paramsBox = document.querySelector('.params')

// 详情页
// 拿到商品  Id
const goodsId = window.sessionStorage.getItem('goodsId')
!goodsId ? window.location.href = 'http://127.0.0.1:5500/xiangmu/src/html/01shouye.html' : getGoodsInfo()
// 发送请求，

async  function getGoodsInfo() {
   console.log('请求商品信息是');
   // 2. 请求数据
   const  res  = await pAjax({
      url: 'http://localhost:8888/goods/item',
      data: { id:goodsId } ,
      dataType: 'json'
   })

//   2-2.查询商品不存在跳转回列表页
if(res.code ===2){
   window.location.href = 'http://127.0.0.1:5500/xiangmu/src/html/01shouye.html'
   return
}
console.log(res.info);
// 2-3. 渲染页面
box.innerHTML = `
<div class="left">
                <img src="${ res.info.img_big_logo }" alt="">
            </div>
            <div class="right">
                <p class="title">
                    ${ res.info.title }
                </p>
                <p>
                    由志豪 购! 物流中心直达
                </p>
                <p class="price">
                   <span class="current"> ￥${ res.info.current_price }</span>
                   <span class="old"> ￥${ res.info.price }</span>
                </p>
                <p class="chima">
                    <button>S</button>
                    <button>L</button>
                    <button>XL</button>
                    <button>2XL</button>
                </p>
                <p class="number">
                    <button>-</button>
                    <input type="text" value="1">
                    <button>+</button>
                </p>
                <p class="btns">
                    <button>加入购物车</button>
                <button>立即购买</button>
                </p>
               
            </div>`
      // 商品参数是直接给的
      // 注意：必须在服务器打开才能看到
      paramsBox.innerHTML = res.info.goods_introduce
}